from flask_wtf import FlaskForm
from wtforms import StringField, SelectField, SubmitField, TextAreaField
import os
from flask import current_app


class EditForm(FlaskForm):
    site_name = StringField('网站名称')
    site_title = StringField('网站标题')
    site_url = StringField('域名')
    site_keyword = StringField('网站关键词')
    site_description = TextAreaField('网站描述')
    site_template = SelectField('模板风格', coerce=str)
    save = SubmitField('保存')

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.site_template.choices = [('default', '默认风格')]
        public_template = os.path.join(current_app.root_path, '..', 'public', 'templates')
        _dir = os.listdir(public_template)
        for i in _dir:
            self.site_template.choices.append((i, i))
